//
//  MMChatroomRankCategoryIndicatorImageView.swift
//  JSTech
//
//  Created by 高得华 on 2020/8/14.
//  Copyright © 2020 华&梅. All rights reserved.
//

import UIKit

class MMChatroomRankCategoryIndicatorImageView: JXCategoryIndicatorImageView {
    
    ///选中的
    //未选中的视图
    var imv_no_select: UIImageView!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        let scale = kMDHPTAutoScale()
        let item_w = 102*scale
        let item_h = 36*scale
        self.indicatorImageViewSize = CGSize(width: item_w, height: item_h)
        self.imv_no_select = UIImageView()
        self.imv_no_select.frame = CGRect(x: 0, y: 0, width: item_w, height: item_h)
        self.addSubview(self.imv_no_select)
        self.indicatorImageView.frame = CGRect(x: 0, y: 0, width: item_w, height: item_h)
        self.verticalMargin = 8*scale
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    ///JXCategoryIndicatorProtocol
    ///categoryView重置状态时调用
    override func jx_refreshState(_ model: JXCategoryIndicatorParamsModel!) {
        super.jx_refreshState(model)
        let x = model.selectedCellFrame.origin.x + (model.selectedCellFrame.size.width - self.indicatorImageViewSize.width)/2;
        var y = (self.superview?.bounds.size.height ?? 0) - self.indicatorImageViewSize.height - self.verticalMargin
        if (self.componentPosition == .top) {
            y = self.verticalMargin
        }
        self.frame = CGRect(x: x, y: y, width: self.indicatorImageViewSize.width, height: self.indicatorImageViewSize.height)
    }
    ///
    override func jx_contentScrollViewDidScroll(_ model: JXCategoryIndicatorParamsModel!) {
        super.jx_contentScrollViewDidScroll(model)
        
    }
    override func jx_selectedCell(_ model: JXCategoryIndicatorParamsModel!) {
        super.jx_selectedCell(model)
        let sel_index = model.selectedIndex
        var sel_name = "chat_room_ranking_list_ribang"
        if sel_index == 1 {
            sel_name = "chat_room_ranking_list_zhoubang"
        }else if sel_index == 2 {
            sel_name = "chat_room_ranking_list_yuebang"
        }
        self.indicatorImageView.image = UIImage(named: sel_name)
        
        let last_index = model.lastSelectedIndex
        var last_name = "chat_room_ranking_list_ribang1"
        if last_index == 1 {
            last_name = "chat_room_ranking_list_zhoubang1"
        }else if last_index == 2 {
            last_name = "chat_room_ranking_list_yuebang1"
        }
        
        self.imv_no_select.image = UIImage(named: last_name)
    }
}
